package com.lehecai.core.api.credit;

import com.lehecai.core.IntegerBeanLabelItem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by zhangzq on 14-2-24.
 */
public class GoodsType extends IntegerBeanLabelItem {

    private static final Logger logger = LoggerFactory.getLogger(GoodsType.class.getName());
    private static final long serialVersionUID = -1;
    private static Map<GoodsClassesType, List<GoodsType>> goodsItems = new HashMap<GoodsClassesType, List<GoodsType>>(64);

    private GoodsClassesType goodsClasses;

    protected GoodsType(String name, int value, GoodsClassesType goodsClasses) {
        super(GoodsType.class.getName(), name, value);

        if (goodsClasses != null) {
            this.goodsClasses = goodsClasses;

            List<GoodsType> list = goodsItems.get(goodsClasses);
            if (list == null) {
                list = new ArrayList<GoodsType>();
                list.add(GoodsType.ALL);		//每一个彩种的集合都添加ALL，供查询使用
                goodsItems.put(goodsClasses, list);
            }
            list.add(this);
        }
    }

    public GoodsClassesType getGoodsClasses() {
        return goodsClasses;
    }

    public void setGoodsClasses(GoodsClassesType goodsClasses) {
        this.goodsClasses = goodsClasses;
    }

    public static Map<GoodsClassesType, List<GoodsType>> getGoodsItems() {
        return goodsItems;
    }

    public static void setGoodsItems(Map<GoodsClassesType, List<GoodsType>> goodsItems) {
        GoodsType.goodsItems = goodsItems;
    }

    public static List<GoodsType> getItemsByGoodsClasses(GoodsClassesType GoodsClasses) {
        return goodsItems.get(GoodsClasses);
    }

    public static GoodsType getItem(int value){
        try {
            return (GoodsType) GoodsType.getResult(GoodsType.class.getName(), value);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return null;
        }
    }

    public static final GoodsType ALL = new GoodsType("全部", -1, null);
    public static final GoodsType GIFT_REAL = new GoodsType("实物礼品", 1, GoodsClassesType.GIFT_EXCHANGE);
    public static final GoodsType GIFT_VIRTUAL = new GoodsType("虚拟礼品", 2, GoodsClassesType.GIFT_EXCHANGE);
    public static final GoodsType SERVICE_LOTTERY = new GoodsType("定制短信", 30 , GoodsClassesType.LOTTERY_SERVICE );
    public static final GoodsType SERVICE_PROP = new GoodsType("道具", 31 , GoodsClassesType.LOTTERY_SERVICE);
    public static final GoodsType SERVICE_RECHARGE = new GoodsType("游戏充值", 32 , GoodsClassesType.LOTTERY_SERVICE);

}
